package top.loonglove.common.util.factory.http;


import top.loonglove.common.util.http.HttpMethod;
import top.loonglove.common.util.http.HttpResponse;
import top.loonglove.common.util.http.HttpStatus;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2021/6/16 0:34
 */
public class HttpResponseFactory {
    private  static final Build BUILD = new Build();
    public synchronized static Build build(){
        return BUILD;
    }
    public synchronized static Build buildSuccess(){
        return build().status(HttpStatus.SUCCESS);
    }


    public static class Build{

        public HttpResponse build(){
            return httpResponse;
        }
        public Build code(int code){
            httpResponse.setCode(code);
            return this;
        }
        public Build error(Throwable error){
            httpResponse.setError(error);
            return this;
        }

        public Build message(String message){
            httpResponse.setMessage(message);
            return this;
        }
        public Build data(Object data){
            httpResponse.setData(data);
            return this;
        }
        public Build requestMethod(HttpMethod method){
            httpResponse.setRequestMethod(method);
            return this;
        }

        public Build status(HttpStatus status){
            httpResponse.setStatus(status);
            return this;
        }
        public Build errorMessage(String errorMessage){
            httpResponse.setErrorMessage(errorMessage);
            return this;
        }

        public Build responseMethod(String method){
            httpResponse.setResponseMethod(method);
            return this;
        }
        public Build token(String token){
            httpResponse.setToken(token);
            return this;
        }

        public Build refreshToken(String refreshToken){
            httpResponse.setToken(refreshToken);
            return this;
        }
        private final HttpResponse httpResponse = new HttpResponse();

        private Build() {
        }
    }
}
